package edu.zju.gis.dbfg.model.scala

import geotrellis.raster.render.{ClassBoundaryType, ColorMap, ColorRamp, ColorRamps, LessThan, LessThanOrEqualTo, Png}

import scala.collection.JavaConverters._

object GeoTrellisTile {
  def getClassBoundaryType(): ClassBoundaryType = {
    LessThanOrEqualTo
  }

  def getDiscreteRandomColorMap(jvs: java.util.List[java.lang.Double], options: ColorMap.Options): ColorMap = {
    var m: Map[Double, Int] = Map()
    val vs = jvs.asScala.toArray.sorted
    val cr = ColorRamps.BlueToOrange.stops(vs.length)
    val colors: List[Int] = cr.toList
    for (i <- 0 until vs.length) {
      m += (vs(i).toDouble -> colors(i))
    }
    ColorMap(m, options)
  }

  def getCustomContinouesColorMap(startColor: Int, endColor: Int, startValue: Int, endValue: Int, stops: Array[Double], options: ColorMap.Options): ColorMap = {
    val cr = ColorRamp(startColor, endColor).stops(stops.length)
    cr.toColorMap(stops,options)
  }

  def transformColorMap(jm: java.util.Map[java.lang.Double, java.lang.Integer], options: ColorMap.Options): ColorMap = {
    val m = jm.asScala
    var om: Map[Double, Int] = Map()
    for (t <- m) {
      val v = t._1.toDouble
      val c = t._2.toInt
      om += (v -> c)
    }
    ColorMap(om, options)
  }
}
